/*
 * @Author: deliteam 462085920@qq.com
 * @Date: 2023-11-30 13:38:35
 * @Description:
 */

import {
  Controller,
  Post,
  Body,
  Get,
  Query,
  UseGuards,
  Delete,
  Request,
  Put,
  Param,
} from '@nestjs/common';
import { PressService } from './press.service';

import { Press } from './press.entity';
import { ApiTags, ApiOperation } from '@nestjs/swagger';
import { JwtAuthGuardUser } from 'src/auth/guards/jwt-auth.guard';
import { CreatePressDto } from './dto/create-press.dto';
import { RemovePressDto } from './dto/remove-press.dto';
import { RetrievePressDto } from './dto/retrieve-press.dto';
import { UpdatePressDto } from './dto/update-press.dto';
import { Log } from 'src/libs/utils';
@ApiTags('荣誉资质')
@Controller('api/press')
export class PressController {
  constructor(private readonly pressService: PressService) {}

  @UseGuards(JwtAuthGuardUser)
  @Post()
  @ApiOperation({ summary: '增加' })
  async create(@Body() createPressDto: CreatePressDto): Promise<Press> {
    return await this.pressService.create(createPressDto);
  }

  // 删除
  @UseGuards(JwtAuthGuardUser)
  @Delete()
  @ApiOperation({ summary: '删除' })
  async remove(
    @Body() removePressDto: RemovePressDto,
    @Request() req,
  ): Promise<any> {
    Log({ req });
    return await this.pressService.delete(removePressDto);
  }

  // 更新
  @UseGuards(JwtAuthGuardUser)
  @Put(':id')
  @ApiOperation({ summary: '更新' })
  async update(
    @Param() params: RetrievePressDto,
    @Body() updatePressDto: UpdatePressDto,
  ): Promise<any> {
    return await this.pressService.update({
      id: params.id,
      updatePressDto,
    });
  }

  @Get()
  @ApiOperation({ summary: '列表' })
  async findAll(@Query() query: any): Promise<Press> {
    return await this.pressService.findAll(query);
  }

  // 根据 id 查找
  @Get(':id')
  @ApiOperation({ summary: '根据 id 查找' })
  async findOneById(@Param() params: RetrievePressDto): Promise<any> {
    return await this.pressService.findOneById(params.id);
  }
}
